import { useEffect, useState } from "react"
import { reqRestrictedCur } from "../api/api"

export const useRestrictedCurriculums = (role, semester) => {
  const [curriculums, setCurriculums] = useState([])

  const getRestrictedCurriculums = (professionalNum, semester) => {
    reqRestrictedCur({ professionalNum, semester }).then(
      res => {
        if (res.status === 200) {
          setCurriculums(() => {
            const options = [{ value: '', label: "" }]
            res.data?.map(item => {
              const option = { value: item.fd_curriculumNum, label: item.fd_curriculumName }
              options.push(option)
            })
            return [...options]
          })
        }
      }
    )
  }


  useEffect(() => {
    if (role !== null) {
      getRestrictedCurriculums(role.fd_professionalNum, semester)
    }
  }, [role,semester])
  return { curriculums }
}